<template>
  <transition name="dialog-fade">
    <div class="dialog-overlay" v-if="isVisible">
      <div class="dialog-content">
        <header class="dialog-header">
          <h3>{{ title }}</h3>
          <button @click="closeDialog">&times;</button>
        </header>
        <main class="dialog-main">{{ content }}</main>
        <footer class="dialog-footer">
          <button @click="confirm" :disabled="confirmDisabled">{{ confirmText }}</button>
          <button @click="closeDialog">{{ cancelText }}</button>
        </footer>
      </div>
    </div>
  </transition>
</template>

<script lang="ts">
import { defineComponent, ref } from 'vue';

export default defineComponent({
  name: 'Dialog',
  props: {
    title: {
      type: String,
      default: '提示'
    },
    content: {
      type: String,
      required: true
    },
    confirmText: {
      type: String,
      default: '确定'
    },
    cancelText: {
      type: String,
      default: '取消'
    },
    confirmDisabled: {
      type: Boolean,
      default: false
    }
  },
  setup(props) {
    const isVisible = ref(false);

    const closeDialog = () => {
      isVisible.value = false;
    };

    const confirm = () => {
      closeDialog();
      if (props.onConfirm) {
        props.onConfirm();
      }
    };

    return {
      isVisible,
      closeDialog,
      confirm,
      title: props.title,
      content: props.content,
      confirmText: props.confirmText,
      cancelText: props.cancelText,
      confirmDisabled: props.confirmDisabled
    };
  }
});
</script>

<style scoped>
.dialog-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background-color: rgba(0, 0, 0, 0.5);
  display: flex;
  justify-content: center;
  align-items: center;
  z-index: 999;
}

.dialog-content {
  background-color: white;
  padding: 20px;
  border-radius: 5px;
  width: 400px;
  min-height: 200px;
  box-shadow: 0 0 10px rgba(0, 0, 0, 0.3);
}

.dialog-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 10px;
}

.dialog-header h3 {
  margin: 0;
}

.dialog-header button {
  background-color: transparent;
  border: none;
  font-size: 20px;
  cursor: pointer;
}

.dialog-main {
  margin-bottom: 20px;
}

.dialog-footer {
  display: flex;
  justify-content: flex-end;
}

.dialog-footer button {
  margin-left: 10px;
  padding: 5px 15px;
  border: none;
  border-radius: 3px;
  cursor: pointer;
  background-color: #4CAF50;
  color: white;
}

.dialog-footer button:last-child {
  background-color: #ccc;
}

.dialog-fade-enter-active,
.dialog-fade-leave-active {
  transition: opacity 0.3s ease;
}

.dialog-fade-enter,
.dialog-fade-leave-to {
  opacity: 0;
}
</style>